package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.TMessageReadDao;
import com.kly.user.db.entity.TMessageReadEntity;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* User: linqu
* Date: 2023-06-26
* Time: 16:49:54.397
*/

@Repository
public class TMessageReadDaoImpl extends AbstractBaseMapper<TMessageReadEntity> implements TMessageReadDao {

    @Override
    public List<TMessageReadEntity> queryUnReadMessages(String userCode) {

        Map<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("readFlag", 0);
        return this.selectByParams(params);
    }

    @Override
    public TMessageReadEntity queryUnReadMessages(String userCode, String messageCode) {

        Map<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("msgCode", messageCode);
//        params.put("readFlag", 0);
        final List<TMessageReadEntity> messageReadEntities = this.selectByParams(params);
        if (CollectionUtils.isEmpty(messageReadEntities)) {
            return null;
        }
        return messageReadEntities.get(0);
    }
}